package com.wanmait.shoppingsys.controller.web;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.shoppingsys.dao.TypeDAO;
import com.wanmait.shoppingsys.vo.Type;
@WebServlet("/TypeController")
public class TypeController extends HttpServlet {
	private TypeDAO typeDAO = TypeDAO.getDAO();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String action = request.getParameter("action");
		if(action==null) return;
		switch(action)
		{
		case "type":
			this.type(request, response);
			break;
		}
	}
	
	
	protected void type(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ArrayList<Type> types = typeDAO.findAll();
		request.setAttribute("types",types);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
